package com.stxx.stiot2.controller;


import okio.Utf8;
import org.noear.solon.annotation.*;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.util.MimeType;


import java.io.InputStream;
import java.nio.charset.StandardCharsets;


@Controller
public class IndexController {
    private String content;
    @Produces(MimeType.TEXT_HTML_VALUE)
    @Get
    @Mapping("/")
    public void index(Context ctx) {
        ctx.contentType(MimeType.TEXT_HTML_VALUE);
        ctx.charset("UTF-8");
        if(content==null){
            try (InputStream inputStream = ClassLoader.getSystemResourceAsStream("static/index.html")){
                assert inputStream != null;
                content = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
            }catch (Exception ex){
            }

        }
        ctx.output(content);
    }
}
